/*------------------------------------------------------------------------
//                          Project CommonLib                           //
------------------------------------------------------------------------*/
#pragma once


#include "APIDefine.h"

namespace
{
    static const char *STR_TOKEN_DELIMIT= " :,[]\t\n";
#ifdef _UNICODE
    static const TCHAR *WSTR_TOKEN_DELIMIT= TEXT(" :,[]\t\n");
#endif

    template<typename T>
    T *GetStrTokn(T* pStr, UINT16 wPos, const T* strDelimit);
    

    template<>
    char *GetStrTokn(char* pStr, UINT16 wPos, const char* strDelimit)
    {   
        if(!pStr) 
			return NULL;
        char *next_token1=NULL;
        char *pToken=NULL;
        
        if(0!=wPos)
        {        
            pToken= STRTOK_ANSI( pStr, strDelimit, &next_token1);        
            while( pToken && ( --wPos > 0))
            {      
                pToken = STRTOK_ANSI( NULL, strDelimit, &next_token1);
            }
        }
        return pToken;
    }
    
    template<>
    TCHAR *GetStrTokn(TCHAR* pStr, UINT16 wPos, const TCHAR* strDelimit)
    {
        TCHAR *next_token1 = NULL;
        TCHAR *pToken = NULL;
        if(0!=wPos)
        {
            pToken = STRTOK_UNI( pStr, strDelimit, &next_token1);
            while( pToken && ( --wPos > 0))
            {      
                pToken = STRTOK_UNI( NULL, strDelimit, &next_token1);
            }
        }
        return pToken;
    }

	std::vector<std::wstring> SplitStr( const std::wstring& source, const std::wstring& separators)
	{
		std::vector<std::wstring> words;
		words.reserve(64);
		std::wstring eachWord;

		for ( size_t i=0; i< source.length(); ++i)
		{
			if( separators.find( source[i] ) == std::wstring::npos )
				eachWord += source[i];
			else
			{
				if( !eachWord.empty() )
				{
					words.push_back( eachWord );
					eachWord.clear();
				}
			}
		}

		if( !eachWord.empty() )		
			words.push_back( eachWord );

		return words;
	}


}


/*------------------------------------------------------------------------

------------------------------------------------------------------------*/
